package com.example.shoppingmallspringboot.controller;

import com.example.shoppingmallspringboot.entity.User;
import com.example.shoppingmallspringboot.service.UserProfileService;
import com.example.shoppingmallspringboot.service.UserService;
import com.example.shoppingmallspringboot.util.JwtConstant;
import com.example.shoppingmallspringboot.vo.UserVo;
import com.example.shoppingmallspringboot.util.FwResult;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

@RestController
@Tag(name = "UserController",description = "用户控制器")
public class UserController {
    @Autowired
    UserService userService;
    @Autowired
    UserProfileService userProfileService;

    @PostMapping("/login")
    @Operation(summary = "用户登录",description = "用户名密码为参数")
    public FwResult login(@RequestBody User user){
        return userService.login(user);
    }

    @PostMapping("/register")
    @Operation(summary = "用户注册",description = "用户名密码为参数")
    public FwResult register(@RequestBody User user){
        return userService.register(user);
    }
    //修改用户名密码
    @PostMapping("/updateUser")
    @Operation(summary = "修改用户名密码",description = "用户名密码为参数")
    public FwResult updateUser(@RequestBody User user) throws IOException {

        return userService.updateUser(user);
    }
    @PostMapping("/userProfile")
    @Operation(summary = "修改用户头像",description = "文件为参数")
    public FwResult userProfile(@RequestParam MultipartFile file,HttpServletRequest request)
            throws IOException {
        /* 获取header中的token信息 */
        String token = request.getHeader(JwtConstant.HEADER_NAME);
        return userProfileService.upload(file,token);
    }

}
